package controller;

import javax.swing.JTextField;

public class TextFieldParsingHelper
{
	public static final double PRICE_NOT_AVAILABLE = 0;
	
	public static int parseIntFromTextField(JTextField textField){
		String text = textField.getText();
		return Integer.parseInt(text);
	}
	
	/***
	 * parses a double from textField (e.g. price value)
	 * if text is empty string, <code>PRICE_NOT_AVAILABLE</code> is returned!
	 * @param textField
	 * @return
	 */
	public static double parseDoubleFromTextField(JTextField textField){
		String text = textField.getText();
		if(text.length() == 0)
		{
			return PRICE_NOT_AVAILABLE;
		}
		return Double.parseDouble(textField.getText());
	}
}
